package com.hj.dapp.business.role.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hj.dapp.business.menu.dto.BindMenuDto;
import com.hj.dapp.business.role.model.Role;
import com.hj.dapp.business.role.service.RoleService;
import com.hj.dapp.common.request.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;

/**
 * @author 胡奥程
 * @version 1.0
 * @date 2023/12/29
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @GetMapping("/get/{id}")
    public Role get(@PathVariable("id") Long id) {
        return roleService.get(id);
    }
    @GetMapping("/getRoles")
    public List<Role> getRoles() {
        return roleService.getRoleList();
    }
    @PutMapping("/save")
    public void save(@RequestBody Role role, Principal principal) {
        roleService.insertRole(role,principal);
    }
    @PostMapping("/update")
    public void update(@RequestBody Role role, Principal principal) {
        roleService.updateRole(role,principal);
    }
    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
        roleService.deleteRole(id);
    }

    @PostMapping("/bindMenu")
    public void bindMenu(@RequestBody BindMenuDto bindMenuDto,Principal principal) {
       roleService.bindMenu(bindMenuDto,principal);
    }
    @PostMapping("/page")
    public IPage<Role> page(@RequestBody PageRequest<Role> pageRequest) {

        return roleService.page(pageRequest);
    }
    @PostMapping("/edit")
    public void edit(@RequestBody Role role,Principal principal) {
        roleService.edit(role,principal);
    }



}
